package com.softserveinc.dao.mapper;

import com.softserveinc.model.User;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Extracts data from database and casts it to User
 */
public class UserResultSetExtractor implements ResultSetExtractor<User> {
    /**
     *
     * @param resultSet - for data extracting
     * @return User object
     * @throws SQLException
     * @throws DataAccessException
     */
    @Override
    public User extractData(ResultSet resultSet) throws SQLException, DataAccessException {
        User user = new User();
        user.setId(resultSet.getInt(1));
        user.setLogin(resultSet.getString(2));
        user.setPass(resultSet.getString(3));
        user.setEmail(resultSet.getString(4));
        user.setSalt(resultSet.getString(5));
        return user;
    }
}
